package com.sit.library.entity.dao;

import com.sit.library.entity.bean.BorrowRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BorrowMapper {

    @Select("select * from borrowrecord where UserID=#{accountId}")
    @Results({
            @Result(column = "RecordID", property = "id"),
            @Result(column = "UserID", property = "userId"),
            @Result(column = "BookID", property = "bookId"),
            @Result(column = "BorrowDate", property = "borrowDate"),
            @Result(column = "ReturnDate", property = "returnDate")
    })
    List<BorrowRecord> findByUser(int accountId);

    @Select({"call AddBorrowRecord(#{accountId}, #{bookId}, @result);",
            "select @result;"})
    String borrowBook(int accountId, int bookId);

    @Select({"call ReturnBook(#{recordId}, #{accountId}, @result);",
            "select @result;"})
    String returnBook(int recordId, int accountId);
}
